package com.lsl.factory_method.example.idcard;

import com.lsl.factory_method.example.framework.Factory;
import com.lsl.factory_method.example.framework.Product;

import java.util.ArrayList;
import java.util.List;

/**
 * ConcreteCreator(具体的创建者)
 * <p>
 * 实现了createProduct方法和registerProduct方法。
 * <p>
 * createProduct方法通过生成IDCard的实例来生产产品
 * registerProduct方法通过将IDCard的owner(持有人)保存到owners字段来实现注册功能
 *
 * @author Zed
 * @description
 * @date 2022/11/1 21:19
 */
public class IDCardFactory extends Factory {

    private List<String> ownerList = new ArrayList();

    @Override
    protected Product createProduct(String owner) {
        return new IDCard(owner);
    }

    @Override
    protected void registerProduct(Product product) {
        ownerList.add(((IDCard) product).getOwner());
    }

    public List getOwners() {
        return ownerList;
    }
}
